package com.temp.filter;

import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class AnonPathChecker {
    private static final List<String> anonPaths = new ArrayList<>();

    @Autowired
    public void init(ShiroFilterFactoryBean shiroFactory) {
        // 从Shiro配置中提取所有标记为anon的路径
        shiroFactory.getFilterChainDefinitionMap().forEach((path, filter) -> {
            if ("anon".equals(filter)) {
                anonPaths.add(path.replace("**", ""));
            }
        });
    }

    public static boolean isAnonPath(String uri) {
        return anonPaths.stream().anyMatch(uri::startsWith);
    }
}
